﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Mvc.Html;
using System.IO;
using System.Linq;
using System.Web.UI;

namespace QLMB.Infrastructure
{
    public static class MyHelpers
    {

        public static MvcHtmlString CheckedRadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object value)
        {
            return CheckedRadioButtonFor(htmlHelper, expression, value, null);
        }

        public static MvcHtmlString CheckedRadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object value, object htmlAttributes)
        {
            var func = expression.Compile();
            var attributes = new RouteValueDictionary(htmlAttributes);
            if ((object)func(htmlHelper.ViewData.Model) == value)
            {
                attributes["checked"] = "checked";
            }
            return htmlHelper.RadioButtonFor(expression, value, attributes);
        }

        public static MvcHtmlString Partial<T>(this HtmlHelper htmlHelper, string partialViewName, T model)
        {
            ViewDataDictionary viewData = new ViewDataDictionary(htmlHelper.ViewData)
            {
                Model = model
            };
            return PartialExtensions.Partial(htmlHelper, partialViewName, model, viewData);
        }
    }
}